package com.airforcehospital;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


@Component
public class AirForceSchedual {
    public static void main(String[] args) throws Exception {

        AirForceService service = new AirForceService();
        service.call();
        /*JSONObject data = new JSONObject();
        data.put("bizToken","dfsgdggfd");
        data.put("verificationCode","gfdgfdgfdgfd");
        data.put("timeout",30000);
        data.put("isLoading","true");
        printJsonObject(data,"{");*/

    }

    @Scheduled(cron = "0 0 15 * * ?")
    //@PostConstruct
    public void run() throws Exception {
        AirForceService service = new AirForceService();
        while (true){
            boolean res = false;
            try{
                res = service.call();
            }catch (Exception e){
                e.printStackTrace();
            }

            System.out.println("返回结果"+res);
            if(res){
                System.out.println("抢到了---------------------------------------------");
                return;
            }
        }
    }

    private static void printJsonObject(JSONObject jsonObject, String prefix) {
        // 获取JSONObject的所有键
        for (String key : jsonObject.keySet()) {
            Object value = jsonObject.get(key);
            if (value instanceof JSONObject) {
                System.out.println(prefix + key + ": {");
                // 递归打印嵌套的JSONObject
                printJsonObject((JSONObject) value, prefix + "  ");
                System.out.println(prefix + "}");
            } else if (value instanceof JSONArray) {
                System.out.println(prefix + key + ": [");
                // 递归打印JSONArray中的元素
                //printJsonArray((JSONArray) value, prefix + "  ");
                System.out.println(prefix + "]");
            } else {
                System.out.println(prefix + key + ": " + value);
            }
        }
    }

}
